import { createRouter, createWebHistory } from 'vue-router';

const pages = import.meta.glob('@/views/**/*.vue');

const routes = Object.entries(pages).map(([pagePath, component]) => {
  let path = pagePath.replace("/src/views", "").replace(".vue", "") || "/";
  let name = path.split("/").filter(Boolean).join("-") || "index";
  if (path === "/HomeView") {
    path = "/";
  }
  return {
    path,
    name,
    component,
  }
});

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: routes,
})

export default router
